unit UFrmSQLFavoriteslProp;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, UToolsList;

type
  TFrmSQLFavoriteslProp = class(TForm)
    lblTitle: TLabel;
    lblProgram: TLabel;
    lblWorkDir: TLabel;
    lblParams: TLabel;
    btnOk: TBitBtn;
    btnCancel: TBitBtn;
    btnHelp: TBitBtn;
    edtTitle: TEdit;
    edtProgram: TEdit;
    edtWorkDir: TEdit;
    edtParam: TEdit;
    btnBrowse: TBitBtn;
    dlgOpen: TOpenDialog;
    procedure btnBrowseClick(Sender: TObject);
    procedure btnOkClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure FormKeyPress(Sender: TObject; var Key: Char);
  private
    procedure SaveProperty;
  public
    AddMode: Boolean; {Add, Edit}
    FileName: string;
    FileCaption: string;

  end;

implementation

{$R *.dfm}

procedure TFrmSQLFavoriteslProp.btnBrowseClick(Sender: TObject);
begin
  if dlgOpen.Execute then
  begin
    edtProgram.Text := dlgOpen.FileName;
    if Trim(edtTitle.Text) = '' then
      edtTitle.Text := StringReplace(ExtractFileName(dlgopen.FileName), ExtractFileExt(dlgOpen.FileName), '', [rfIgnoreCase]);
  end;
end;

procedure TFrmSQLFavoriteslProp.btnOkClick(Sender: TObject);
begin
  if Trim(edtTitle.Text) = '' then
    Exit;
  SaveProperty;
end;

procedure TFrmSQLFavoriteslProp.SaveProperty;
begin
  FileCaption := edtTitle.Text;
  FileName := ExtractFileDir(edtProgram.Text);
  Self.ModalResult := mrOk;
end;

procedure TFrmSQLFavoriteslProp.FormShow(Sender: TObject);
begin
  if AddMode then
  begin
    edtTitle.Text := '';
    edtProgram.Text := '';
    edtWorkDir.Text := '';
    edtParam.Text := '';
  end else
  begin
    edtTitle.Text := FileCaption;
    edtProgram.Text := FileName;
  end;
end;

procedure TFrmSQLFavoriteslProp.FormKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
    btnOk.Click;
  if Key = #27 then
    btnCancel.Click;
end;

end.

